<?php

class Login extends CI_Controller {

	public function index()
	{
	   //$data['main_content'] = 'login_view';
	   //$this->load->view('include/template', $data);
       $this->load->view('login_view');
	}
    
    public function validate_credentials() {
        $this->load->model('user_model');
        $result = $this->user_model->validate();

        if($result == false) // user credintials validated ...
        {
            $this->index();
        }
        else
        {
            $data = array();
            foreach($result as $row)
            {
                $data = array(
                    'username' => $this->input->post('username'),
                    'user_type_id' => $row->user_type_id,
                    'is_logged_in' => true
                );
            }

            $this->session->set_userdata($data);
            redirect('site/members_area');    
        }
            
    }
    
}
